package com.mdc.mansion.core.common.config;

import com.mdc.mansion.common.exception.BusinessException;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class ConfigSettingUtil {
	
	private static Object lock  = new Object();
	private static ConfigSettingUtil instance =null;
	private static Properties properties = new Properties();
	
	/**
	 *
	 */
	@SuppressWarnings("static-access")
	private ConfigSettingUtil()
	{
		InputStreamReader file  = null ;
		try {
			file =   new InputStreamReader(ConfigSettingUtil.class.getClassLoader().getResourceAsStream("config/web-config.properties"),"UTF-8");
			
			ConfigSettingUtil.class.getClassLoader().getResource("config/web-config.properties");
			
			properties.load(file);
		}catch(Exception e)
		{
			e.printStackTrace();
			System.out.println("未找到wxconfig.properties配置文件");
			throw new BusinessException("未找到wxconfig.properties配置文件");
		}
	}
	
	/**
	 * 
	 * @return
	 */
	public static ConfigSettingUtil getInstance() {
		synchronized(lock) {
			if(null == instance) {
				instance = new ConfigSettingUtil();
			}
		}
		return (instance);
	}
	
	
	/**
	 * 获取所有配置参数
	 * @return
	 */
	public Properties getAllWxProperties()
	{
		return ConfigSettingUtil.properties;
	}

	

	/**
	 * 根据单个确定的key获取配置文件的内容
	 * @param propertiesKey
	 * @return
	 */
	public String getDefineWxProperties(String propertiesKey)
	{
		return String.valueOf(properties.get(propertiesKey));
	}
	
	public static void main(String[] args) {
		String test = ConfigSettingUtil.getInstance().getDefineWxProperties("refund_call_back");
		System.out.println(test);
		
	}
	
}
